/****************************************************************************
*  Title: design.sc
*  Author: Anthony Schaefer, Umar Butt, Talha Ansari
*  Date: 04/01/2010
*  Description: Behavior that does the computation
****************************************************************************/

#include <stdio.h>
//import "c_queue";
import "communication";

/* if want to use with c_queue somehow */
//behavior design (i_receiver firstData, i_receiver operatorData,
//				i_receiver secondData,  i_sender outputData)
behavior design (TwoWayHandShaking firstData, TwoWayHandShaking operatorData,
				TwoWayHandShaking secondData, TwoWayHandShaking outputData)
{

	float a, b, c;
	char d;

	void main(void) {
	
		while (1)
		{
			/* if want to use with c_queue somehow */
			//firstData.receive(&a, 1);
			//operatorData.receive(&d, 1);
			//secondData.receive(&b, 1);
			
			/* Receive user entered data for computation */
			a = firstData.Receive();
			d = operatorData.Receive();
			b = secondData.Receive();
			
			/* Do proper computation */
			if (d == '*')
			{
				c = a * b;
			}
			
			if (d == '/')
			{
				c = a / b;
			}
			
			if (d == '+')
			{
				c = a + b;
			}
			
			if (d == '-')
			{
				c = a - b;
			}
			
			/* if want to use with c_queue somehow */
			//outputData.send(&c, 1);
			
			/* Send result back to inputoutput behavior */
			outputData.Send(c);
		}
	
	}
};

